from django.db import models
import datetime


# Create your models here.

class user(models.Model):
    id = models.AutoField(primary_key=True, db_index=True)
    nickname = models.CharField(max_length=255, null=True, default='')
    password = models.CharField(max_length=255, null=True)
    account = models.CharField(max_length=255, unique=True)
    avatar = models.URLField(max_length=255, null=True)
    QQ = models.IntegerField(null=True)
    email = models.EmailField(null=True)
    status = models.BooleanField(default=True)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)
    last_login_time = models.DateTimeField(null=True)
    admin = models.BooleanField(default=False)

    class Meta:
        get_latest_by = "-create_time"
        unique_together = (("nickname", "account"),)
        db_table = 'mblog_user'
        default_permissions = ()
        permissions = (
            ("select_user", "查看用户"),
            ("change_user", "修改用户"),
            ("delete_user", "删除用户"),
        )


class token(models.Model):
    id = models.AutoField(primary_key=True, db_index=True)
    user = models.OneToOneField("user.user", on_delete=models.CASCADE)
    token = models.CharField(max_length=100, db_index=True)
    expire_time = models.DurationField(default=datetime.timedelta(minutes=30))
    update_time = models.DateTimeField(auto_now=True)
    create_time = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = "mblog_token"
